//字符串截取
var getArgs = function () { //作用是获取当前网页的查询条件
    var args = new Object(); //声明一个空对象
    var query = window.location.search.substring(1); // 取查询字符串，如从http://www.snowpeak.org/testjs.htm?a1=v1&a2=&a3=v3#anchor 中截出 a1=v1&a2=&a3=v3。
    var pairs = query.split("&"); // 以 & 符分开成数组
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('='); // 查找 "name=value" 对
        if (pos == -1) continue; // 若不成对，则跳出循环继续下一对
        var argname = pairs[i].substring(0, pos); // 取参数名
        var value = pairs[i].substring(pos + 1); // 取参数值
        value = decodeURIComponent(value); // 若需要，则解码
        args[argname] = value; // 存成对象的一个属性
    }
    return args; // 返回此对象
};

//清除cookie
function clearCookie() {
    var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
    if (keys) {
        for (var i = keys.length; i--;)
            document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
    }
}

var args = new getArgs();
var token = args.token;

//跳转登录
function goLogin(url) {
    if (isFromApp == "true") {
        location.href = "icbccs://u_login" + locationSearch(); //客户端返回登录
    } else {
        if (url) {
            location.href = url;  //web返回登录
        } else {
            location.href = "login.html" + locationSearch();  //web返回登录
        }
    }
}

function transStringToBlank(str) {
    if (str == 'undefined' || str == undefined || str == 'null' || str == null) {
        return "";
    } else {
        return str;
    }
}

function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]); return null;
}

var StringUtils = {  
        isEmpty: function(input) {  
            return input == 'null' || input == null || input == '' || input== 'undefined' || input == undefined;  
        },  
        isNotEmpty: function(input) {  
            return !this.isEmpty(input);  
        },  
        isBlank: function(input) {  
            return input == 'null' || input == null || /^\s*$/.test(input);  
        },  
        isNotBlank: function(input) {  
            return !this.isBlank(input);  
        },  
        trim: function(input) {  
            return input.replace(/^\s+|\s+$/, '');  
        },  
        trimToEmpty: function(input) {  
            return input == null ? "" : this.trim(input);  
        },  
        startsWith: function(input, prefix) {  
            return input.indexOf(prefix) === 0;  
        },  
        endsWith: function(input, suffix) {  
            return input.lastIndexOf(suffix) === 0;  
        },  
        contains: function(input, searchSeq) {  
            return input.indexOf(searchSeq) >= 0;  
        },  
        equalsIgnoreCase: function(input1, input2) {  
            return input1.toLocaleLowerCase() == input2.toLocaleLowerCase();  
        },  
        containsWhitespace: function(input) {  
            return this.contains(input, ' ');  
        },  
        //生成指定个数的字符  
        repeat: function(ch, repeatTimes) {  
            var result = "";  
            for(var i = 0; i < repeatTimes; i++) {  
                result += ch;  
            }  
            return result;  
        },  
        deleteWhitespace: function(input) {  
            return input.replace(/\s+/g, '');  
        },
        rightPad: function(input, size, padStr) {  
            return input + this.repeat(padStr, size);  
        },  
        leftPad: function(input, size, padStr) {  
            return this.repeat(padStr, size) + input;  
        },
        //中文校验  
        isChinese: function(input) {  
            return /^[\u4E00-\u9FA5]+$/.test(input);  
        }
};
